﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="aaagctrl.js" />
/// <reference path="SBT.debug.js" />
Manager = function(host)
{
    Manager.initializeBase(this,[host]);
}

Manager.prototype = 
{
    onSilverlightLoaded : function(slControl, args)
    {
        
        var radioArray = new Array();
        var plugin = this.get_plugin();
        var pluginContent = plugin.content;
        var downloader = plugin.createObject("downloader"); 
        var mgr = this;
        
        downloader.addEventListener("completed", function()
        {
            var radioDown = downloader.getResponseText("radioDown.xaml");
            var radioUp = downloader.getResponseText("radioUp.xaml");
            var radioEnter = downloader.getResponseText("radioEnter.xaml");
            var radioLeave = downloader.getResponseText("radioLeave.xaml");
            
            var checkDown = downloader.getResponseText("checkDown.xaml");
            var checkUp = downloader.getResponseText("checkUp.xaml");
            var checkEnter = downloader.getResponseText("checkEnter.xaml");
            var checkLeave = downloader.getResponseText("checkLeave.xaml");
            for(var i=0; i<5; i++)
            {
                var radioBtn = $create(SBT.ToggleButton, {element:pluginContent.findName("radio"+i), 
                        plugin:plugin,
                        mouseDownTemplate:radioDown,
                        mouseUpTemplate:radioUp,
                        mouseEnterTemplate:radioEnter,
                        mouseLeaveTemplate:radioLeave,
                        isPushed:false},null,null,null);
                Array.add(radioArray, radioBtn);
            }
            var radioList = $create(SBT.ToggleButtonList, 
                    {id:"radioBtnList",items:radioArray, behavior:SBT.ToggleButtonListBehavior.radioButtonList, plugin:plugin},
                    {selectionChanged:Function.createDelegate(mgr, mgr.onRadioSelectionChanged)},null,null);
                    
                    
            var checkArray = new Array();
            for(var i=0; i<5; i++)
            {
                var checkBtn = $create(SBT.ToggleButton, {element:pluginContent.findName("Check"+i), 
                        plugin:plugin,
                        mouseDownTemplate:checkDown,
                        mouseUpTemplate:checkUp,
                        mouseEnterTemplate:checkEnter,
                        mouseLeaveTemplate:checkLeave,
                        isPushed:false},null,null,null);
                Array.add(checkArray, checkBtn);
            }
            var checkList = $create(SBT.ToggleButtonList, 
                    {id:"checkBtnList",items:checkArray, behavior:SBT.ToggleButtonListBehavior.checkboxButtonList, plugin:plugin},
                    {selectionChanged:Function.createDelegate(mgr, mgr.onCheckboxSelectionChanged)},null,null);
        });
        downloader.open("GET", "Templates.zip");
        downloader.send();
    },
    onRadioSelectionChanged : function(sender,args)
    {
        var txtblock = this.get_plugin().content.findName("txtSelectedRadio");
        var text = "Selection: ";
        for(var i=0;i<sender.get_selectedItems().length;i++)
        {
            text+=sender.get_selectedItems()[i].get_element().name+"; ";
        }
        txtblock.Text = text;
    },
    onCheckboxSelectionChanged : function(sender,args)
    {
        var txtblock = this.get_plugin().content.findName("txtSelectedCheck");
        var text = "Selection: ";
        for(var i=0;i<sender.get_selectedItems().length;i++)
        {
            text+=sender.get_selectedItems()[i].get_element().name+"; ";
        }
        txtblock.Text = text;
    }
}
Manager.registerClass("Manager", SBT.SLManager);